package calao.client.util;

public class DayTime 
{
	
	int hours;
	
	int minutes;

	public DayTime(int hours, int minutes)
	{
		setHours(hours);
		setMinutes(minutes);
	}
	
	public int getHours() 
	{
		return hours;
	}

	public void setHours(int hours) 
	{
		if (hours<0 || hours>23) throw new IllegalArgumentException();
		this.hours = hours;
	}

	public int getMinutes() 
	{
		return minutes;
	}

	public void setMinutes(int minutes) 
	{
		if (minutes<0 || minutes>59) throw new IllegalArgumentException();
		this.minutes = minutes;
	}

	public static DayTime parse(String text)
	{
		String[] tokens = text.split(":");
		if (tokens.length!=2) throw new IllegalArgumentException();
		return new DayTime(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]));
	}
	
	public String toString()
	{
		StringBuffer buffer = new StringBuffer();
		if (hours<10) buffer.append('0');
		buffer.append(hours);
		buffer.append(':');
		if (minutes<10) buffer.append('0');
		buffer.append(minutes);
		return buffer.toString();
	}

}
